import allConst from "@/Json.js"
import uniIcon from '@/components/uni-icon/uni-icon.vue';
import uniCalendar from '@/components/uni-calendar/uni-calendar.vue';
import * as Api from '@/syApis/syAddOrder/syaddApis.js';
import goodModel from '@/components/ShowModl.vue';
import addOrderList from '@/components/selectGoodsItemBrach/selectGoodsItemBrach';
import settingOption from '@/components/settingOption/settingOption';
import selectSimple from '@/components/selectGoodsItem/selectSimple';
import * as rules from "@/common/barcodeRules.js"
export default {
	data() {
		return {
			//往来单位当前索引
			index1: -1,
			//单据编号
			BillNo: "",
			//单据日期
			BillDate: "",
			//制单人
			CreateName: "",
			//银行编号pick列表
			BankPicker: [],
			//银行编号当前索引
			BankIndex: -1,
			//银行编号源数组
			BankIndexList: [],
			//收款方式当前索引
			giveMoneyIndex: -1,
			//收款方式pick列表
			giveMoneyIndexList: [],
			//收款方式源数组
			PayForFs: [],
			//往来单位源数组
			ClientMessage: [],
			//往来单位pick数组
			picker1: [],
			//业务员
			OperatorList: [],
			//业务员pick数组
			picker2: [],
			//业务员当前索引
			index2: -1,
			TabCur: 0,
			list: [{
				name: '单据信息',
			}],
			BillType: "",
			BillName: "",
			//制单人
			CreateName: uni.getStorageSync("UserName"),
			//收款金额
			parForMoney: 0,
			VIPID: 0,
			//是否选中了商品
			isSelectGood: false,
			searchKey: "",
			//应付款单据列表
			OrderGoodsList: [],
			//多规格商品弹框
			isShowScanModel: false,
			//扫码返回的单据
			scanGoodList: [],
			//选中的单据
			NowSelectGoods: {},
			selectLookMore: -1,
			//选择批号的弹框显隐
			showSmodle: true,
			//仓库名
			StoreName: "",
			//仓库ID
			StoreID: "",
			//仓库列表
			StoreList: [],
			//批号列表
			storeList: [],
			//批号
			Inventorybatch: "",
			isChange: false,
			//查看更多提示
			TbHeaderMore: "查看更多",
			//是否查看更多表头
			isLookHeaderMore: false,
			//当前选择的业务员条目
			SelectOptionsObj: {
				OperatorName: "",
				OperatorID: ""
			},
			//当前选择的批次
			SelectBatchObj: {
				Inventorybatch: "",
				StoreName: "",
				StoreID: ""
			},
			modalName: null,
			SearchOptionName: "",
			//当前选择的仓库条目
			SelectStoreObj: {
				StoreName: "",
				StoreID: ""
			},
			SearchStoreName: "",
			TempStoreList: [],
			TempOptionList: [],
			isShowTip: false,
			isUserRoot: {},
			unLoadimg: '../../static/unUplad.png',
			// cgSettingLocation: {},
			modalNames: null,
			//本地保存的设置数组
			cgSettingLocation: {},
			//打印份数
			printNum: 1,
			//打印机编号
			printCode: 0,
			isChangeShow: false,
			barCodeRelus: {
				Rule_Separate: "",
				Rule_Bar: "",
				Rule_Code: "",
				Rule_Num: "",
				Rule_Num_Demical: "",
				Rule_Price: "",
				Rule_Price_Demical: "",
				Rule_SN: "",
				Rule_BatchNo: "",
				Rule_Color: "",
				Rule_Size: "",
				Separate_IsEnable: "",
				BarRule_All_Length: "",
				BarRule_CutBar_Start: "",
				BarRule_CutBar_End: "",
				BarRule_CutCode_Start: "",
				BarRule_CutCode_End: "",
				BarRule_CutNum_Start: "",
				BarRule_CutNum_End: "",
				BarRule_CutNum_Demical: "",
				BarRule_CutPrice_Start: "",
				BarRule_CutPrice_End: "",
				BarRule_CutPrice_Demical: "",
				BarRule_CutSN_Start: "",
				BarRule_CutSN_End: "",
				BarRule_CutBatchNo_Start: "",
				BarRule_CutBatchNo_End: "",
				BarRule_CutColor_Start: "",
				BarRule_CutColor_End: "",
				BarRule_CutSize_Start: "",
				BarRule_CutSize_End: "",
				Cut_IsEnable: "",
				Ignore_Befor: "",
				Ignore_After: ""
			},
			//条码分割数组
			barRulesList: [],
			//是否启用分隔规则0 分割规则1 2不启用
			SeparateIsEnable: 0,
			Inventorybatch: "",
			isBillCheckQx: false,
			allConstUrl: allConst.imgurlHeader,
			SelectClientObj: {
				ClientID: "",
				ClientName: ""
			},
			isGetPriceFollowMessage: [],
			AddGoodsTempList: [],
			isScanGoodMessage: [],
			tempScanGoodList: [],
			Remark: "",
			isHide:false,
			isSearch:false
		}
	},
	components: {
		uniCalendar,
		uniIcon,
		goodModel,
		addOrderList,
		settingOption,
		selectSimple
	},
	onShow() {
		this.$eventHub.$off('pdPcListen');
		this.$eventHub.$off('fireData');
		this.$eventHub.$off('fires');
		this.$eventHub.$off('AddChangeBill');
		this.isHide = false;
		this.isSearch = false;
	},
	computed: {
		goodAllAmount() {
			var Ammount = 0;
			var that = this;
			this.OrderGoodsList.forEach(item => {
				Ammount += that.compuTaxMoney(item);
			});
			return Math.round(Ammount * 100) / 100;
		},
		OrderGoodsListLength() {
			var AllCount = 0;
			var that = this;
			this.OrderGoodsList.forEach(item => {
				AllCount += parseFloat(item.Qty);
			});
			return AllCount;
		}
	},
	watch: {
		//判断添加获取价格方案是否全部完成
		isGetPriceFollowMessage(newVal) {
			console.log(newVal.length);
			var that = this;
			if (newVal.length == this.AddGoodsTempList.length && newVal.length != 0) {
				setTimeout(function() {
					uni.hideLoading();
					that.isSearch = false;
					if (that.AddGoodsTempList.length > 0) {
						that.isInOrderList(that.AddGoodsTempList);
					}

				}, 200);
			}
		}
		// ,
		// //判断扫码数据获取价格方案是否全部完成
		// isScanGoodMessage(newVal) {
		// 	var that = this;
		// 	if (newVal.length == this.tempScanGoodList.length && newVal.length != 0) {
		// 		setTimeout(function() {
		// 			uni.hideLoading();
		// 			let data = {
		// 				data: {
		// 					ResultMsg: that.tempScanGoodList
		// 				}
		// 			}
		// 			that.scanGoodList = that.pullBarCodeGoods(data).data.ResultMsg;
		// 			if (that.scanGoodList.length == 1) {
		// 				that.selectGoodsList(0);
		// 			} else {
		// 				if (that.scanGoodList.length > 0) {
		// 					that.modalName = "StoreScanGoodModal";
		// 				}

		// 			}
		// 		}, 500);
		// 	}
		// }
	},
   onHide(){
	 this.isHide = true;  
   },
	onLoad(options) {
		var _this = this;
		
		// Api.registerReciver(function(barcode) {
		// 	_this.searchKey = barcode;
		// 	_this.search(false);
		// });
	
		console.log(options.BillName);
		this.BillName = options.BillName;
		this.getBillTime();
		this.BillType = '10'
		this.GetOperatorMessage();
		this.GetStoreMessage();
		let PDA_Module_Android = uni.getStorageSync("PDA_Module_Android"); //获取单据权限
		PDA_Module_Android = JSON.parse(PDA_Module_Android);
		var that = this;
		PDA_Module_Android.forEach((item, index) => {
			if (this.BillName == item.ModuleName) {
				that.isUserRoot = item;
			}
		});
		uni.setNavigationBarTitle({
			title: options.BillName
		})
		if (options.type == 1) {
			console.log(options.oldOrder);
			let oldOrder = JSON.parse(options.oldOrder);
			this.oldOrder = oldOrder;
			this.BillNo = oldOrder.BillNo;
			this.BillID = oldOrder.BillID;
			this.BillDate = oldOrder.BillTime;
			this.CreateName = oldOrder.OpenName;
			this.SelectOptionsObj.OperatorID = oldOrder.EmpID;
			this.SelectOptionsObj.OperatorName = oldOrder.EName
			this.SelectStoreObj.StoreName = oldOrder.stockName;
			this.SelectStoreObj.StoreID = oldOrder.StoreID;
			this.Comment = oldOrder.Comment;
			this.SelectBatchObj.StoreID = oldOrder.StoreID;
			this.SelectBatchObj.StoreName = oldOrder.stockName;
			this.SelectBatchObj.Inventorybatch = oldOrder.Inventorybatch;
			this.Remark = oldOrder.Remark;
			// this.CreateName = oldOrder.OpenName;
			this.getBillDetail(oldOrder.BillID);
			this.isChange = true;
		} else {
			this.isChange = false;
		}

		let setting = uni.getStorageSync("setting" + this.BillType, "");
		if (setting === "") {
			this.cgSettingLocation = "";
		} else {
			this.cgSettingLocation = JSON.parse(setting);
		};
		let barCodeRelus = uni.getStorageSync("BarCode", "");
		if (barCodeRelus != "") {
			this.barCodeRelus = JSON.parse(barCodeRelus);;
		}
		let SystemSettingInfo = uni.getStorageSync("SystemSettingInfo", ""); //存储系统设置
		SystemSettingInfo = JSON.parse(SystemSettingInfo);
		SystemSettingInfo.forEach((item, index) => {
			if (item.SystemName == '单据是否直接审核') {
				if (item.Value == "1") {
					that.isBillCheckQx = true;
				}
				// console.log(item.Value);
			}

		});
		
		try{
			Api.registerReciver(function(barcode) {
			
				_this.searchKey = barcode;
				
				_this.search(false);
			});
		}catch(e){
			//TODO handle the exception
		}
	},
	onPageScroll(e) {
		if (e.scrollTop > 400) {
			this.isShowTip = true;
		} else {
			this.isShowTip = false;
		}
	},
	onUnload(){
		console.log("页面卸载");
		try {
			Api.unRegisterReciver();
		} catch (e) {
			//TODO handle the exception
		}
		
	},
	methods: {
		getBillTime(){
			let date = new Date();
			var month = date.getMonth() + 1;
			if (month < 10) {
				month = "0" + month
			}
			var day = date.getDate();
			if (day < 10) {
				day = "0" + day;
			}
			this.BillDate = date.getFullYear() + "-" + month + "-" + day;
		},
		xpDy() {
			if (this.isChange) {
				// console.log(this.$refs.settingOption._data);
				// this.$refs.settingOption._data.modalPrintName = "printSetting";
				// this.modalNames = 
				console.log("小票打印ssssss");
				let item = {
					Save_M_Data_Json: this.oldOrder,
					Save_D_Data_Json: this.OrderGoodsList
				}
				console.log(item);
				let mac_address = uni.getStorageSync("bluetoothName", "");
				if (mac_address == "") {
					Api.showTip("请先连接打印机");
					return;
				}
				rules.print(mac_address, item, this.BillType);

			} else {
				Api.showTip("请先查询单据");
			}
		},
		//获取价格方案
		pullGoodsInfo(GoodsItem) {
			console.log(GoodsItem);
			this.AddGoodsTempList = GoodsItem;
			var that = this;
			for (var i in this.AddGoodsTempList) {
				this.XH_Get_PriceFollowMessage(this.AddGoodsTempList[i], i, function(res, index) {
					if (!that.AddGoodsTempList[index].isSet) {
						that.AddGoodsTempList[index].Price = res;
						that.AddGoodsTempList[index] = that.DiscountPrice(that.AddGoodsTempList[index]);
						that.AddGoodsTempList[index] = that.Amount(that.AddGoodsTempList[index]);
					}

				});
			}

		},
		//价格跟踪
		XH_Get_PriceFollowMessage: async function(priceItem, Filter = "", success, isScan = false) {
			var that = this;
			let data = {
				GoodsID: priceItem.GoodsID,
				UnitID: priceItem.UnitID,
				BillName: this.BillName,
				URate: priceItem.urate,
				ClientID: this.SelectClientObj.ClientID || "",
				StoreID: this.SelectBatchObj.StoreID
			}
			Api.XH_Get_PriceFollowMessage(data, function(res) {
				// console.log(Filter);
				if (isScan) {
					that.isScanGoodMessage.push(Filter);
				} else {
					that.isGetPriceFollowMessage.push(Filter);
				}
				if (res.state) {
					if (res.data.ResultMsg != "") {
						// that.PriceList = res.data.ResultMsg;
						// priceItem.Price = that.PriceList[0].Price;
						success(res.data.ResultMsg[0].Price, Filter);
					} else if (res.data.ErrorMsg == '获取登录信息失败') {
						Api.showTip(res.data.ErrorMsg);
					} else {
						Api.showTip(res.data.ErrorMsg);
					}

				} else {

				}
			});
		},
		defaultSetting() {
			this.clearAll();
			let settingList = uni.getStorageSync("settingList", "");
			if (settingList != "") {
				settingList = JSON.parse(settingList);
				// console.log(this.settingList);
				settingList.forEach((item, index) => {

					if (item.Default_Name == "业务员") {
						this.SelectOptionsObj.OperatorName = item.Default_Value;
						this.SelectOptionsObj.OperatorID = item.Default_ID;
					}
					// if (item.Default_Name == '仓库') {
					// 	this.SelectStoreObj.StoreName = item.Default_Value;
					// 	this.SelectStoreObj.StoreID = item.Default_ID;
					// }
					// if (item.Default_Name == '供应商') {
					// 	this.SelectClientObj.ClientName = item.Default_Value;
					// 	this.SelectClientObj.ClientID = item.Default_ID;
					// }
				});
			}
		},
		//切换商品列表
		changeSelectShow() {
			this.isChangeShow = !this.isChangeShow;
		},
		DateChange(e) {
			this.BillDate = e.detail.value;
		},
		filterStore(e) {
			let value = e.detail.value;
			this.TempStoreList = [];
			var that = this;
			this.StoreList.forEach((item, index) => {
				if (item.StoreName.indexOf(value) > -1) {
					that.TempStoreList.push(item);
				}
			});
			if (that.TempStoreList.length == 0) {
				Api.showTip("查无数据");
			}
		},
		filterOption(e) {
			let value = e.detail.value;
			this.TempOptionList = [];
			var that = this;
			this.OperatorList.forEach((item, index) => {
				if (item.OperatorName.indexOf(value) > -1) {
					that.TempOptionList.push(item);
				}
			});
			if (that.TempOptionList.length == 0) {
				Api.showTip("查无数据");
			}
		},
		//返回顶部
		scrollTop() {
			uni.pageScrollTo({
				scrollTop: 0,
				duration: 0
			});
		},
		//获取单据明细
		getBillDetail(BillNo) {
			this.BillID = BillNo;
			let data = {
				BillID: BillNo
			};
			var that = this;
			Api.SelectBillInventoryDetail(data, function(res) {
				if (res.state) {
					if (res.data.ErrorMsg == '获取登录信息失败') {

					} else if (res.data.ErrorMsg != '') {
						Api.showTip(res.data.ErrorMsg);
					} else {
						res.data.ResultMsg.forEach((item, index) => {
							res.data.ResultMsg[index].Price = item.inPrice;
							res.data.ResultMsg[index].Discount = 100;
							res.data.ResultMsg[index].Tax = 0;
							res.data.ResultMsg[index].stockqty = item.StoreQty;
							res.data.ResultMsg[index].urate = 0;
							res.data.ResultMsg[index].IsGift = item.IsGift ? 1 : 0;
							res.data.ResultMsg[index] = that.DiscountPrice(item);
							res.data.ResultMsg[index] = that.Amount(item);
							res.data.ResultMsg[index].urate = item.URate;
							res.data.ResultMsg[index].ProductionDate = item.ProductionDate.split(" ")[0];
							res.data.ResultMsg[index].validityDate = item.validityDate.split(" ")[0];
							if (res.data.ResultMsg[index].Goods_Image_Path1 == '' || typeof res.data.ResultMsg[index].Goods_Image_Path1 ==
								'undefined') {
								res.data.ResultMsg[index].Goods_Image_Path1 = that.unLoadimg;
							} else {
								res.data.ResultMsg[index].Goods_Image_Path1 = allConst.pictureUrl + res.data.ResultMsg[index].Goods_Image_Path1;
							}
							res.data.ResultMsg[index] = that.DiscountPrice(item);
							res.data.ResultMsg[index] = that.Amount(item);
							res.data.ResultMsg[index].payCount = item.PayTotal;

						})
						that.OrderGoodsList = res.data.ResultMsg;

					}
				}
			})
		},
		// DiscountPrice(item) {
		// 	return parseFloat(item.Price) * (parseFloat(item.Discount) / 100) * (1 + parseFloat(
		// 		item.Tax) / 100);
		// },
		// //计算总价
		// Amount(item) {
		// 	return parseFloat(item.Price) * parseFloat(item.Qty) * (parseFloat(item.Discount) / 100) * (1 + parseFloat(
		// 		item.Tax) / 100);
		// 	// return  PFPrice;
		// },
		DiscountPrice(item) {
			item.DiscountPrice = parseFloat(item.Price) * (parseFloat(item.Discount) / 100) * (1 + parseFloat(
				item.Tax) / 100);

			return item;
		},
		//计算总价
		Amount(item) {
			item.Amount = parseFloat(item.Price) * parseFloat(item.Qty) * (parseFloat(item.Discount) / 100) * (1 + parseFloat(
				item.Tax) / 100);
			// return  PFPrice;
			return item;
		},
		lookOrder() {
			// this.AddChangeBill();
			if(this.isChange){
				uni.redirectTo({
					url: "../selPurchasePd/selPurchase?BillName=" + this.BillName
				})
			}else{
				uni.navigateTo({
					url: "../selPurchasePd/selPurchase?BillName=" + this.BillName
				})
			}
			
		},
		AddChangeBill() {
			var _this = this;
			//当前选择的商品的临时列表
			// var NewGoodListTemp = this.OrderGoodsList;
			this.$eventHub.$on('AddChangeBill', function(data) {
				let oldOrder = JSON.parse(data);
				_this.oldOrder = oldOrder;
				_this.BillNo = oldOrder.InventoryNo;
				_this.BillID = oldOrder.BillID;
				_this.BillDate = oldOrder.InventoryTime.split(" ")[0];
				_this.CreateName = oldOrder.OpenName;
				_this.SelectOptionsObj.OperatorID = oldOrder.EmpID;
				_this.SelectOptionsObj.OperatorName = oldOrder.EName
				_this.SelectStoreObj.StoreName = oldOrder.stockName;
				_this.SelectStoreObj.StoreID = oldOrder.StoreID;
				_this.Remark = oldOrder.Remark;
				_this.SelectBatchObj.StoreID = oldOrder.StoreID;
				_this.SelectBatchObj.StoreName = oldOrder.stockName;
				_this.SelectBatchObj.Inventorybatch = oldOrder.Inventorybatch;
				_this.getBillDetail(oldOrder.BillID);
				_this.isChange = true;
				_this.$eventHub.$off('AddChangeBill');
			});
		},
		//获取仓库
		GetStoreMessage(Filter = "") {
			let data = {
				Filter: Filter
			}
			var that = this;
			Api.GetStoreMessage(data, function(res) {
				if (res.state) {
					if (res.data.ErrorMsg == "获取登录信息失败") {
						Api.showTip("登录超时");
					} else if (res.data.ErrorMsg != "") {
						Api.showTip(res.data.ErrorMsg);
					} else {
						that.StoreList = res.data.ResultMsg;
						that.TempStoreList = res.data.ResultMsg;
					}
				} else {

				}
			});
		},
		//搜索仓库
		searchStore() {
			if (this.SearchStoreName != '') {
				let Filter = "StoreName like '%" + this.SearchStoreName + "%'";
				this.GetStoreMessage(Filter);
			} else {
				this.GetStoreMessage();
			}
		},
		//清空单据
		sureClear() {
			var that = this;
			uni.showModal({
				title: "是否清空单据",
				content: "清空后不可恢复,是否确认",
				success(res) {
					if (res.confirm) {
						that.clearAll();
					}
				}
			})
		},
		//清空单据
		clearAll(isBill=false) {
			this.BillNo = "";
			//当前选择的业务员条目
			this.OrderGoodsList = [];
			this.SelectOptionsObj = {
				OperatorID: "",
				OperatorName: ""
			};
			this.Remark = "";
			//当前选择的批次
			this.SelectBatchObj = {
				Inventorybatch: "",
				StoreName: "",
				StoreID: ""
			}
			if(isBill){
				
					this.GetNewOrderNo(false);
				
			}
			
			this.isChange = false;
		},
		//删除选择的商品
		deleteSelectGood(e) {
			var _this = this;
			let index = e.currentTarget.detail.deleteIndex;
			Api.showConfirm("是否删除此商品", function(state) {
				if (state) {
					_this.removeItem(index);
				} else {

				}
			})
		},
		showModal(e) {
			this.modalName = e.currentTarget.dataset.target
		},
		hideModal(e) {
			this.modalName = null
		},
		//选择仓库
		selectStore(index) {
			this.SelectStoreObj = this.StoreList[index];
			this.modalName = null;
		},
		//搜索业务员
		searchOption() {
			if (this.searchOption != '') {
				let Filter = "OperatorName like '%" + this.SearchOptionName + "%'";
				this.GetOperatorMessage(Filter);
			} else {
				this.GetOperatorMessage();
			}
		},
		// 选择业务员
		selectOptions(index) {
			this.SelectOptionsObj = this.OperatorList[index];
			console.log(this.SelectOptionsObj);
			this.modalName = null;
		},
		//查看表头更多信息
		lookHeaderMore() {
			this.isLookHeaderMore = !this.isLookHeaderMore;
			if (this.isLookHeaderMore) {
				this.TbHeaderMore = "收起更多"
			} else {
				this.TbHeaderMore = "查看更多"
			}
		},
		//修改还是新增单据
		isChangeOrder() {
			//如果新增
			if (this.isChange) {
				this.Change_Bill_Order();

			} else {
				this.GetNewOrderNo(true);
			}
		},
		//修改单据
		Change_Bill_Order() {
			this.searchKey = "";
			let Save_M_Data_Json = [];
			if (this.OrderGoodsList.length == 0 && this.BillType != 18) {
				Api.showTip("请至少选择一件单据");
				return;
			}
			if (this.BillNo == "") {
				Api.showTip("请先获取单号");
				return;
			}
			console.log(this.SelectOptionsObj);
			if (this.SelectOptionsObj.OperatorID == "") {
				Api.showTip("请先选择业务员");
				return;
			}
			if (this.SelectBatchObj.Inventorybatch == "") {
				Api.showTip("请先选择盘点批号");
				return;
			}
			let CreateID = uni.getStorageSync("UserCode");
			let item = {
				InventoryNo: this.BillNo,
				InventoryTime: this.BillDate,
				Inventorybatch: this.SelectBatchObj.Inventorybatch,
				StoreID: this.SelectBatchObj.StoreID,
				EmpID: this.SelectOptionsObj.OperatorID,
				CreateID: CreateID,
				Remark: this.Remark
			};
			var Save_D_Data_Json = [];
			var UnitQty = 0;
			this.OrderGoodsList.forEach((item, index) => {
				if (item.urate == 0) {
					UnitQty = item.UnitQty;
				} else {
					UnitQty = item.urate * item.Qty;
				}
				var item = {
					GoodsID: item.GoodsID,
					UnitID: item.UnitID,
					UnitQty: UnitQty + "",
					URate: item.urate + "",
					Qty: item.Qty + "",
					StoreQty: item.stockqty + "",
					inPrice: item.Price + "",
					BatchNo: item.BatchNo,
					ProductionDate: item.ProductionDate,
					validityDate: item.validityDate
				}
				Save_D_Data_Json.push(item);
			});
			let data = {};
			data = {
				BillID: this.BillID,
				Save_M_Data_Json: JSON.stringify(item),
				Save_D_Data_Json: JSON.stringify(Save_D_Data_Json)
			};
			var self = this;
			Api.Change_Bill_Inventory(data, function(res) {
				if (res.state) {
					if (res.data.ErrorMsg == '获取登录信息失败') {

					} else if (res.data.ErrorMsg != '') {
						Api.showTip(res.data.ErrorMsg);
					} else {
						Api.showTip("修改成功");
						self.clearAll(true);
					}
				}
			})
		},
		//添加商品
		addSelectGoods() {
			if (this.NowSelectGoods.payCount == 0) {
				Api.showTip("请输入本次结算额");
				return;
			}
			//判断商品是否存在 0否 1 是
			var flag = 0;
			var _this = this;
			// console.log(this.NowSelectGoods);
			this.OrderGoodsList.forEach((item, index) => {
				if (item.BillNo == _this.NowSelectGoods.BillNo) {
					_this.OrderGoodsList[index].payCount = _this.payCount;
					flag = 1;
				}
			});
			if (flag == 0) {
				this.OrderGoodsList.push(this.NowSelectGoods);
			}
			this.NowSelectGoods = {};
			this.isSelectGood = false;
		},
		//查询批号
		GetInventoryMessage() {
			let isClient = 2
			uni.navigateTo({
				url: '../pdPcSelect/pdPcSelect'
			})
			var that = this;
			this.$eventHub.$on('pdPcListen', function(data) {
				that.SelectBatchObj = JSON.parse(data);
				console.log(that.SelectBatchObj);
				that.$eventHub.$off('pdPcListen');
			})


		},
		//选择扫码商品
		choosesGoods(index) {
			this.StoreName = this.storeList[index].StoreName;
			this.StoreID = this.storeList[index].StoreID;
			this.Inventorybatch = this.storeList[index].Inventorybatch;
			// console.log(this.NowSelectGoods);
			this.isShowScanModel = false;
			// this.isSelectGood = true;
		},
		//扫码获取商品
		tel: function() {
			// Api.showTip("网页端暂不支持此功能");
			// return;
			this.current = -1;
			// 调起条码扫描
			var _this = this;
			uni.scanCode({
				scanType: 'barCode',
				success: function(res) {
					// _this.isGetPriceFollowMessage = [];
					_this.isGetPriceFollowMessage = [];
					var flag = true;
					if (_this.cgSettingLocation.QuiteAddGoodInfo[0].state) {
						flag = false;
					} else {
						flag = true;
					}
					_this.GetBarcodeGoodsMessageModel(res.result,flag);
					_this.GetPayBill(res.result);
					console.log('条码类型：' + res.scanType);
					console.log('条码内容：' + res.result);
				},
				fail(e) {
					console.log(e);
				}
			});
		},
		search(flag = true) {
			//如果不是扫描头
			// if (flag) {

			// } else {
			//如果是开启了快速扫描
			if (this.cgSettingLocation.QuiteAddGoodInfo[0].state) {
				flag = false;
			} else {
				flag = true;
			}

			// }
			if (this.SelectBatchObj.Inventorybatch == '') {
				Api.showTip("请选择盘点批次");
				return;
			}
			if(this.isHide){
				return;
			}
			if(this.isSearch){
				Api.showTip("数据处理中,请稍后");
				return;
			}
			this.searchKey  =this.searchKey.replace(/^\s+|\s+$/g,"");
			this.isScanGoodMessage = [];
			this.isGetPriceFollowMessage = [];
			let finalObj = rules.getRulesStr(this.cgSettingLocation.BarcodeRule[0].state,
				this.barCodeRelus, this.searchKey);
			console.log(finalObj);
			//判断启用的条码规则
			this.SeparateIsEnable = finalObj.SeparateIsEnable;
			this.barRulesList = finalObj.barRulesList;
			this.Inventorybatch = finalObj.Inventorybatch;
			// this.searchKey = ;
			this.GetBarcodeGoodsMessageModel(finalObj.searchKey, flag);
			// GetPayBill(this.searchKey);
		},

		// GetBarcodeGoodsMessageModel(barcode) {
		// 	let data = {
		// 		BillName: this.BillName,
		// 		BarCode: barcode,
		// 		Model: "="
		// 	};
		// 	var that = this;
		// 	Api.GetBarcodeGoodsMessageModel(data, function(res) {
		// 		console.log(res.data.ResultMsg);
		// 		// Api.showTip(res.data.ResultMsg);
		// 		if (res.data.ResultMsg != '') {
		// 			if (res.data.ResultMsg.length == 0) {
		// 				Api.showTip("查无数据");
		// 			}
		// 			res.data.ResultMsg.forEach((item,index)=>{
		// 				res.data.ResultMsg[index].Qty = 1;
		// 				res.data.ResultMsg[index].Discount = 100;
		// 				res.data.ResultMsg[index].Tax = 0;
		// 				res.data.ResultMsg[index].Remark = "";
		// 				res.data.ResultMsg[index].GoodsStorm = 0;
		// 				res.data.ResultMsg[index].Price = res.data.ResultMsg[index].PFPrice;
		// 				res.data.ResultMsg[index].barcode = res.data.ResultMsg[index].BarCode;
		// 				res.data.ResultMsg[index].URate = res.data.ResultMsg[index].urate;
		// 				res.data.ResultMsg[index].StoreID = that.SelectStoreObj.StoreID;
		// 				res.data.ResultMsg[index].stockqty = Math.round(res.data.ResultMsg[index].stockqty * 100) / 100;
		// 				res.data.ResultMsg[index].PFPrice = Math.round(res.data.ResultMsg[index].PFPrice * 100) / 100;
		// 				res.data.ResultMsg[index].ProductionDate = "";
		// 				res.data.ResultMsg[index].validityDate = "";
		// 				res.data.ResultMsg[index].IsGift = 0;
		// 			});
		// 			
		// 			that.scanGoodList = res.data.ResultMsg;
		// 			that.modalName = "StoreScanGoodModal";
		// 		} else if (res.data.ResultMsg == "") {
		// 			Api.showTip("查无数据");
		// 		} else if (res.data.ErrorMsg == "获取登录信息失败") {
		// 
		// 		} else {
		// 
		// 		}
		// 	})
		// },
		//扫码获取单据
		GetPayBill(Filter) {
			let data = {
				ClientID: this.ClientId,
				Filter: "BillNo=" + Filter
			}
			var self = this;
			Api.GetPayBill(data, function(res) {
				if (res.state) {
					if (res.data.ErrorMsg == '获取登录信息失败') {

					} else if (res.data.ErrorMsg != '') {
						Api.showTip(res.data.ErrorMsg);
					} else {
						res.data.ResultMsg.forEach((item, index) => {
							item.payCount = 1;
						});
						self.scanGoodList = res.data.ResultMsg;
						that.modalName = "StoreScanGoodModal";
						that.searchKey = "";
					}
				} else {
					Api.showTip("服务器开小差了");
				}
			})
		},
		//按下事件
		// clickNow(index) {
		// 	console.log("按下");
		// 	this.endTime = (new Date()).valueOf();
		// 	var numTime = 0;
		// 	var _this = this;
		// 	this.touchTime = setInterval(function() {
		// 		numTime++;
		// 		if (numTime == 1) {
		// 			clearInterval(_this.touchTime);
		// 			Api.showConfirm("是否删除此商品", function(state) {
		// 				if (state) {
		// 					_this.removeItem(index);
		// 				} else {

		// 				}
		// 			})
		// 		}
		// 	}, 1000);
		// },
		//移除
		removeItem($index) {
			//删除操作存储未被删除的数据
			var newGoodList = [];
			this.OrderGoodsList.forEach((item, index) => {
				if (index != $index) {
					newGoodList.push(item);
				}
			});
			this.OrderGoodsList = newGoodList;
		},
		//抬起事件
		// clickEnd(index) {
		// 	clearInterval(this.touchTime);
		// 	let nowTime = (new Date()).valueOf();
		// 	if (nowTime - this.endTime <= 1000) {
		// 		this.changeInfo(index);
		// 	}
		// },
		//修改商品信息
		changeInfo(e) {
			this.AddListens();
			let index = e.currentTarget.detail.changeIndex;
			uni.setStorageSync("ChangeGoodData", JSON.stringify(this.OrderGoodsList[index]));
			uni.navigateTo({
				url: "../goodListRkCk/selectGoodInfo?selectIndex=" +
					index + "&orderType=" + this.BillType + "&Inventorybatch=" + this.SelectBatchObj.Inventorybatch + "&StoreID=" +
					this.SelectBatchObj.StoreID
			});
		},
		//获取更多商品信息
		lookGoodsInfo(index) {
			if (this.selectLookMore == index) {
				this.selectLookMore = -1;
			} else {
				this.selectLookMore = index;
			}
		},
		//计算折扣后的总金额
		compuTaxMoney(item) {
			let PFPrice = "";
			PFPrice = parseFloat(item.Price) * parseFloat(item.Qty) * (parseFloat(item.Discount) / 100) * (1 + parseFloat(
				item.Tax) / 100);

			return PFPrice;
		},
		selectGoodsList(index) {
			this.AddListen();
			this.isSearch = true;
			var Inventorybatch = this.Inventorybatch;
			if (Inventorybatch == "") {
				Inventorybatch = this.SelectBatchObj.Inventorybatch;
			}
			if (Inventorybatch == "") {
				Api.showTip("请先选择盘点批次");
				return;
			}
			this.modalName = "";
			this.searchKey = "";
			uni.setStorageSync("ChangeGoodData", JSON.stringify(this.scanGoodList[index]));
			uni.navigateTo({
				url: "../goodListRkCk/addScanGood?index=" + index + "&StoreID=" + this.SelectBatchObj.StoreID + "&IsCx=" + this.BillType +
					"&BillName=" + this.BillName + "&Inventorybatch=" + Inventorybatch +
					"&orderType=10"
			});
		},
		gogoodlist() {
			if (this.BillNo == "") {
				Api.showTip("请先创建新单");
				return;
			};
			if (this.SelectBatchObj.StoreID == '') {
				Api.showTip("请选择盘点批号");
				return;
			}
			this.AddListen();
			this.isGetPriceFollowMessage = [];
			var isSelectMore = this.cgSettingLocation.isMoreSelectGood[0].state ? "1" : "0";
			// var isSelectMore = this.cgSettingLocation.
			uni.navigateTo({
				url: "../goodListRkCk/goodList?StoreID=" + this.SelectBatchObj.StoreID + "&orderType=" + this.BillType +
					"&BillName=" + this.BillName + "&isSelectMore=" + isSelectMore + "&Inventorybatch=" + this.SelectBatchObj.Inventorybatch
			});
		},
		//获取转账方式
		GetPayModeMessage() {
			let data = {};
			var that = this;
			Api.GetPayModeMessage(data, function(res) {
				console.log(res.data.ResultMsg);
				if (res.state) {
					// Api.showTip(res.data.ResultMsg);
					if (res.data.ResultMsg != '') {
						if (res.data.ResultMsg.length == 0) {
							Api.showTip("查无数据");
							return;
						}
						let responseData = res.data.ResultMsg;
						that.PayForFs = responseData;
						responseData.forEach((item, index) => {
							that.giveMoneyIndexList.push(item.name);
						});
					} else if (res.data.ResultMsg == "") {
						Api.showTip("查无数据");
					} else if (res.data.ErrorMsg == "获取登录信息失败") {

					} else {

					}
				} else {
					Api.showTip("服务器开小差了");
				}
			})
		},
		//银行账号
		BankPickerChange(e) {
			this.BankIndex = e.detail.value
			// this.BankID = this.BankIndexList[e.detail.value].BankID;
		},
		//转账方式e
		giveMoneyChange(e) {
			this.giveMoneyIndex = e.detail.value
			// this.PayMode = this.PayForFs[e.detail.value].id
		},
		//
		PickerChange1(e) {
			console.log(e)
			this.index1 = e.detail.value
		},
		PickerChange2(e) {
			console.log(e)
			if (e.detail.value == -1) {
				this.index2 = 0
			} else {
				this.index2 = e.detail.value
			}

		},
		//查询往来单位
		GetClientMessage() {
			this.picker1 = [];
			let data = {};
			var that = this;
			Api.GetClientMessage(data, function(res) {
				if (res.state) {
					if (res.data.ErrorMsg == "获取登录信息失败") {
						Api.showTip("登录超时");
					} else if (res.data.ErrorMsg != "") {
						Api.showTip(res.data.ErrorMsg);
					} else {
						that.ClientMessage = res.data.ResultMsg;
						res.data.ResultMsg.forEach((item, index) => {
							that.picker1.push(item.ClientName);
						});
					}
				} else {

				}
			});
		},
		//通过条码扫描商品
		GetBarcodeGoodsMessageModel(barcode, flag = true) {
			this.isSearch = true;
			uni.showLoading({
				title: "加载中..."
			})
			let Model = "";
			if (this.cgSettingLocation.BarLike[0].state) {
				Model = "%like"
			} else if (this.cgSettingLocation.BarLike[1].state) {
				Model = "like%"
			} else if (this.cgSettingLocation.BarLike[2].state) {
				Model = "like"
			} else {
				Model = "="
			}
			let data = {
				BillName: this.BillName,
				BarCode: barcode,
				Model: Model,
				StoreID: this.SelectBatchObj.StoreID
			};
			var that = this;
			Api.GetBarcodeGoodsMessageModel(data, function(res) {
				that.searchKey = "";
				console.log(res.data.ResultMsg);
				// Api.showTip(res.data.ResultMsg);
				if (res.data.ResultMsg != '') {
					if (res.data.ResultMsg.length == 0) {
						uni.hideLoading();
						Api.showTip("查无数据");
						that.isSearch = false;
						return;
					}
					res.data.ResultMsg.forEach((item, index) => {
						if (res.data.ResultMsg[index].Goods_Image_Path1 == "") {
							res.data.ResultMsg[index].Goods_Image_Path1 = that.unLoadimg
							// console.log("进来了");
						} else {
							console.log("----进了了");
							res.data.ResultMsg[index].Goods_Image_Path1 = that.allConstUrl + res.data.ResultMsg[index].Goods_Image_Path1;
							// res.data.ResultMsg[index].Goods_Image_Path1 = tempUrl;
							// console.log(tempUrl);
						}
					})
					if (flag) {
						uni.hideLoading();
						that.scanGoodList = that.pullBarCodeGoods(res).data.ResultMsg;
						// that.isSearch = false;
						if (that.scanGoodList.length == 1) {
							that.selectGoodsList(0);
							
						} else {
							if (that.scanGoodList.length > 0) {
								that.modalName = "StoreScanGoodModal";
								that.isSearch = false;
							}

						}
						// uni.showLoading({
						// 	title: "加载中.."
						// })
						// that.tempScanGoodList = that.pullBarCodeGoods(res).data.ResultMsg;
						// that.tempScanGoodList.forEach((item, index) => {
						// 	that.XH_Get_PriceFollowMessage(item, index, function(item, i) {
						// 		that.tempScanGoodList[i].Price = item;
						// 		that.tempScanGoodList[index] = that.DiscountPrice(that.tempScanGoodList[index]);
						// 		that.tempScanGoodList[index] = that.Amount(that.tempScanGoodList[index]);
						// 		// priceItem.Price = that.PriceList[0].Price;
						// 		console.log(item);
						// 	}, true);
						// });
					} else {
						// that.scanGoodList = res.data.ResultMsg;
						// let NewGoodListTemp = that.OrderGoodsList;
						// 	uni.showLoading({
						// 		title: "加载中..",
						// mask:false
						// 	})
						// that.pullGoodsInfo(that.pullBarCodeGoods(res).data.ResultMsg);
						res = that.pullBarCodeGoods(res).data.ResultMsg;
						let resultList = [];
						resultList.push(res[0]);
						// console.log(resultList);
						that.pullGoodsInfo(resultList);
					}
				} else if (res.data.ResultMsg == "") {
					Api.showTip("查无数据");
					that.isSearch = false;
					uni.hideLoading();
				} else if (res.data.ErrorMsg == "获取登录信息失败") {
					uni.hideLoading();
					that.isSearch = false;
				} else {
					uni.hideLoading();
					that.isSearch = false;
				}
			})
		},
		pullBarCodeGoods(res) {
			var that = this;
			res.data.ResultMsg.forEach((item, index) => {
				res.data.ResultMsg[index].Qty = 1;
				let result = rules.ruleFinalRes(that.SeparateIsEnable, that.barCodeRelus, that.barRulesList, res, that.searchKey,
					index);
				res = result.result;
				res.data.ResultMsg[index].Discount = 100;
				res.data.ResultMsg[index].Tax = 0;
				res.data.ResultMsg[index].Remark = "";
				res.data.ResultMsg[index].GoodsStorm = 0;
				// res.data.ResultMsg[index].Price = res.data.ResultMsg[index].PFPrice;
				res.data.ResultMsg[index].barcode = res.data.ResultMsg[index].BarCode;
				res.data.ResultMsg[index].URate = res.data.ResultMsg[index].urate;
				res.data.ResultMsg[index].StoreID = that.SelectBatchObj.StoreID;
				// res.data.ResultMsg[index].StoreID2 = that.SelectInStoreObj.StoreID;
				res.data.ResultMsg[index].stockqty = Math.round(res.data.ResultMsg[index].stockqty * 100) / 100;
				// res.data.ResultMsg[index].PFPrice = Math.round(res.data.ResultMsg[index].PFPrice * 100) / 100;
				res.data.ResultMsg[index].ProductionDate = "";
				res.data.ResultMsg[index].validityDate = "";
				res.data.ResultMsg[index].BatchNo = "";
				res.data.ResultMsg[index].IsGift = 0;
				// if (res.data.ResultMsg[index].Goods_Image_Path1 == "") {
				// 	res.data.ResultMsg[index].Goods_Image_Path1 = that.unLoadimg
				// 	// console.log("进来了");
				// } else {
				// 	res.data.ResultMsg[index].Goods_Image_Path1 = that.allConstUrl + res.data.ResultMsg[index].Goods_Image_Path1;
				// }
				res.data.ResultMsg[index] = that.DiscountPrice(res.data.ResultMsg[index]);
				res.data.ResultMsg[index] = that.Amount(res.data.ResultMsg[index]);

			});
			return res;
		},
		//点击获取单号
		GetNewOrderNo(isPull) {
			this.getBillTime();
			if (!isPull) {
				this.defaultSetting();
			} else {
				if (this.BillNo == "") {
					Api.showTip("请先创建新单!");
					return;
				}
				if (this.OrderGoodsList.length == 0 && this.BillType != 18) {
					Api.showTip("请至少选择一件单据");
					return;
				}

				// console.log(this.SelectOptionsObj);
				if (this.SelectOptionsObj.OperatorID == "") {
					Api.showTip("请先选择业务员");
					return;
				}
				if (this.SelectBatchObj.Inventorybatch == "") {
					Api.showTip("请先选择盘点批号");
					return;
				}
			}
			if (this.isUserRoot.IsBill_AddNew == "") {
				Api.showTip("无新增权限");
				return;
			}
			let data = {
				BillType: this.BillType,
				IsAdd: isPull ? 1 : 0,
				BillDate: this.BillDate
			};
			var that = this;
			Api.NewOrderNo(data, function(res) {
				if (res.state) {
					if (res.data.ErrorMsg == "获取登录信息失败") {
						Api.showTip("登录超时");
					} else if (res.data.ErrorMsg != "") {
						Api.showTip(res.data.ErrorMsg);
					} else {
						that.BillNo = res.data.ResultMsg.BillNo
						if (isPull) {
							that.AddBillOrder();
						}
					}
				} else {

				}
			});
		},
		//商品修改事件监听
		AddListens() {
			var _this = this;
			this.$eventHub.$on('fireData', function(data) {
				// let NewGoodInfo = JSON.parse(data.NewGoodInfo);
				// _this.OrderGoodsList[data.index].Tax = parseFloat(NewGoodInfo.Tax);
				// _this.OrderGoodsList[data.index].Discount = parseFloat(NewGoodInfo.Discount);
				// _this.OrderGoodsList[data.index].StoreID = NewGoodInfo.StoreID;
				// _this.OrderGoodsList[data.index].Qty = parseFloat(NewGoodInfo.Qty);
				// _this.OrderGoodsList[data.index].BatchNo = NewGoodInfo.BatchNo;
				// _this.OrderGoodsList[data.index].ProductionDate = NewGoodInfo.ProductionDate;
				// _this.OrderGoodsList[data.index].ValidityDate = NewGoodInfo.ValidityDate;
				// _this.OrderGoodsList[data.index].BatchNo == item.BatchNo;
				// console.log(_this.OrderGoodsList[data.index]);
				// _this.selectLookMore = -1;
				let NewGoodInfo = JSON.parse(data.NewGoodInfo);
				_this.OrderGoodsList[data.index] = NewGoodInfo;
				let OrderGoodsList = Object.assign([], _this.OrderGoodsList);
				_this.pullBlissfulGoods(data.index, OrderGoodsList);
				// _this.OrderGoodsList = OrderGoodsList;
				_this.$eventHub.$off('fireData');
			});
		},
		//相同的参数商品合并
		pullBlissfulGoods(index, OrderGoodsList) {
			let item = OrderGoodsList[index];
			OrderGoodsList.forEach(($item, $index) => {
				if ($index != index) {
					if ($item.GoodsID == item.GoodsID && $item.UnitID == item.UnitID &&
						parseFloat($item.urate) == parseFloat(item.urate) && parseFloat($item.Price) ==
						parseFloat(item.Price) && $item
						.StoreID == item.StoreID && item.IsGift == $item.IsGift && $item.ProductionDate ==
						item.ProductionDate &&
						$item.validityDate == item.validityDate &&
						parseFloat($item.Tax) == parseFloat(item.Tax) && parseFloat($item.Discount) ==
						parseFloat(item.Discount) && $item.BatchNo == item.BatchNo && $item.Qty > 0
					) {
						OrderGoodsList[index].Qty = parseFloat(OrderGoodsList[index].Qty) + parseFloat($item.Qty);
						OrderGoodsList[index].Remark = $item.Remark;
						OrderGoodsList[index].Amount = OrderGoodsList[index].Amount + parseFloat($item.Amount);
						$item.Remark = "";
						$item.Amount = "";
						$item.Qty = 0;
					}
				}
			});
			this.OrderGoodsList = Object.assign([], OrderGoodsList);
		},
		//增加商品事件监听
		AddListen() {
			var _this = this;
			//当前选择的商品的临时列表
			var NewGoodListTemp = this.OrderGoodsList;
			this.$eventHub.$on('fires', function(data) {
				// let GoodsItem = JSON.parse(data);
				// GoodsItem.forEach((item, index) => {
				// 	if (!_this.IsInOrderList(item).isIn) {
				// 		NewGoodListTemp.push(item);
				// 	}
				// });
				// this.OrderGoodsList = NewGoodListTemp;
				let GoodsItem = JSON.parse(data);
				uni.showLoading({
					title: "加载中..",
					mask: false
				})
				// console.log(_this.OrderGoodsList);
				_this.pullGoodsInfo(GoodsItem);
				_this.$eventHub.$off('fires');
			});
		},
		//判断加入的商品是否存在
		isInOrderList(GoodsItem) {
			let state = this.cgSettingLocation.onlyAddNum[0].state;
			let NewGoodListTemp = [];
			this.OrderGoodsList.forEach((item, index) => {
				NewGoodListTemp.push(item);
			});
			// GoodsItem = tempList;
			var unAddGood = [];
			GoodsItem.forEach((item, index) => {
				let items = this.IsInOrderList(item, state);
				if (items.isUnAdd) {
					unAddGood.push(index);
				} else {
					if (!items.isIn) {
						NewGoodListTemp.push(item);
					}
				}
			});
			if (unAddGood.length > 0) {
				Api.showTip("批号商品批号不能为空");
			}
			// return;
			// return;
			this.OrderGoodsList = NewGoodListTemp;
			this.searchKey = "";
			this.isSearch = false;
		},
		//判断当前增加的商品是否存在
		IsInOrderList(item) {
			if (item.BatchNo == "" && item.IsBatch) {
				item.isUnAdd = true;
				return item;
			}
			for (var i = 0; i < this.OrderGoodsList.length; i++) {
				// console.log(this.OrderGoodsList[i].Price,item.Price);
				// console.log(this.OrderGoodsList[i].StoreID,item.StoreID);
				// console.log(this.OrderGoodsList[i].IsGift,item.IsGift);
				// console.log(this.OrderGoodsList[i].StoreID2,item.StoreID2);
				// console.log(this.OrderGoodsList[i].ProductionDate,item.ProductionDate);
				// console.log(this.OrderGoodsList[i].validityDate,item.validityDate);
				// console.log(this.OrderGoodsList[i].Tax,item.Tax);
				// console.log(this.OrderGoodsList[i].Discount,item.Discount);
				// console.log(this.OrderGoodsList[i].BatchNo,item.BatchNo);
				if (this.cgSettingLocation.onlyAddNum[0].state) {
					if (this.OrderGoodsList[i].GoodsID == item.GoodsID && this.OrderGoodsList[i].Qty > 0) {
						item.isIn = true;
						this.OrderGoodsList[i].Qty = parseFloat(this.OrderGoodsList[i].Qty) + parseFloat(item.Qty);
						item.Price = this.OrderGoodsList[i].Price;
						item.Discount = this.OrderGoodsList[i].Discount;
						item.Tax = this.OrderGoodsList[i].Tax;
						this.OrderGoodsList[i].Amount += this.getOnlyNumAmount(item);
						return item;
					}
				} else {
					if (this.OrderGoodsList[i].GoodsID == item.GoodsID && this.OrderGoodsList[i].UnitID == item.UnitID &&
						parseFloat(this.OrderGoodsList[i].urate) == parseFloat(item.urate) && parseFloat(this.OrderGoodsList[i].Price) ==
						parseFloat(item.Price) && this.OrderGoodsList[i]
						.StoreID == item.StoreID && item.IsGift == this.OrderGoodsList[i].IsGift && this.OrderGoodsList[i].ProductionDate ==
						item.ProductionDate &&
						this.OrderGoodsList[i].validityDate == item.validityDate &&
						parseFloat(this.OrderGoodsList[i].Tax) == parseFloat(item.Tax) && parseFloat(this.OrderGoodsList[i].Discount) ==
						parseFloat(item.Discount) && this.OrderGoodsList[
							i].BatchNo == item.BatchNo && this.OrderGoodsList[i].Qty > 0) {
						item.isIn = true;
						this.OrderGoodsList[i].Qty = parseFloat(this.OrderGoodsList[i].Qty) + parseFloat(item.Qty);
						this.OrderGoodsList[i].Remark = item.Remark;
						this.OrderGoodsList[i].Amount += parseFloat(item.Amount);
						return item;
					}
				}

			}
			item.isIn = false;
			return item;
		},
		getOnlyNumAmount(item) {
			return parseFloat(item.Price) * parseFloat(item.Qty) * (parseFloat(item.Discount) / 100) * (1 + parseFloat(
				item.Tax) / 100); // return  PFPrice;

		},
		//获取银行账号
		GetBankMessage() {
			var that = this;
			let data = {};
			Api.GetBankMessage(data, function(res) {
				if (res.state) {
					if (res.data.ErrorMsg == "获取登录信息失败") {
						Api.showTip("登录超时");
					} else if (res.data.ErrorMsg != "") {
						Api.showTip(res.data.ErrorMsg);
					} else {
						console.log(res);
						let responseData = res.data.ResultMsg;
						that.BankIndexList = responseData;
						responseData.forEach((item, index) => {
							that.BankPicker.push(item.BankName);
						});
					}
				} else {
					console.log(res);
				}
			});
		},
		open() {
			this.$refs.calendar.open();
		},
		open1() {
			this.$refs.calendar1.open();
		},
		open2() {
			this.$refs.calendar2.open();
		},
		confirm(e) {
			this.BillDate = e.fulldate;
		},
		confirm1(e) {
			this.ProductionDate = e
		},
		confirm2(e) {
			this.ValidityDate = e
		},
		//获取业务员列表
		GetOperatorMessage() {
			let data = {
				Filter: ""
			}
			this.picker2 = [];
			var that = this;
			Api.GetOperatorMessage(data, function(res) {
				if (res.state) {
					if (res.data.ErrorMsg == "获取登录信息失败") {
						Api.showTip("登录超时");
					} else if (res.data.ErrorMsg != "") {
						Api.showTip(res.data.ErrorMsg);
					} else {
						let responseData = res.data.ResultMsg;
						that.OperatorList = responseData;
						that.TempOptionList = responseData;
					}
				} else {

				}
			});
		},
		//提交单据
		AddBillOrder() {
			this.searchKey = "";
			let Save_M_Data_Json = [];

			let CreateID = uni.getStorageSync("UserCode");
			let item = {
				InventoryNo: this.BillNo,
				InventoryTime: this.BillDate,
				Inventorybatch: this.SelectBatchObj.Inventorybatch,
				StoreID: this.SelectBatchObj.StoreID,
				EmpID: this.SelectOptionsObj.OperatorID,
				CreateID: CreateID,
				Remark: this.Remark
			};
			var Save_D_Data_Json = [];
			this.OrderGoodsList.forEach((item, index) => {
				var item = {
					GoodsID: item.GoodsID,
					UnitID: item.UnitID,
					UnitQty: (item.urate * item.Qty) + "",
					URate: item.urate + "",
					Qty: item.Qty + "",
					StoreQty: item.stockqty + "",
					inPrice: item.Price + "",
					BatchNo: item.BatchNo,
					ProductionDate: item.ProductionDate,
					validityDate: item.validityDate

				}
				Save_D_Data_Json.push(item);
			});
			let data = {};
			data = {
				Save_M_Data_Json: JSON.stringify(item),
				Save_D_Data_Json: JSON.stringify(Save_D_Data_Json)
			};
			var _this = this;
			Api.AddBillInventory(data, function(res) {
				if (res.state) {
					if (res.data.ErrorMsg == '获取登录信息失败') {

					} else if (res.data.ErrorMsg != '') {
						Api.showTip(res.data.ErrorMsg);
					} else {
						Api.showTip("保存成功");
						_this.BillID = res.data.BillID;
						setTimeout(function() {
							if (_this.cgSettingLocation.ycDy[0].state) {
								_this.isPrintOrder(true, res.data.BillID);
							}
							if (_this.cgSettingLocation.ycDy[1].state) {
								_this.isPrintOrder(false, res.data.BillID);
							}
							//如果没有勾选打印
							if (!_this.cgSettingLocation.ycDy[0].state && !_this.cgSettingLocation
								.ycDy[1].state) {
								if (_this.BillType != 10) {
									if (!_this.isBillCheckQx) {
										if (_this.cgSettingLocation.djSh[0].state) {
											_this.isBillCheck(true);
										}
										if (_this.cgSettingLocation.djSh[1].state) {
											_this.isBillCheck(false);
										}
									} else {
										_this.isBillCheck(false);
									}
								} else {
									Api.showTip("盘点单无法进行审核操作!");
								}
							}
						}, 500);

						_this.clearAll(true);
					}
				}
			})
		},
		//打印份数监听
		getPrintNum(e) {
			this.printNum = e.detail.value
		},
		//打印机编号选择事件
		radioChange(e) {
			this.printCode = e.detail.value
		},
		onNavigationBarButtonTap(e) {
			const index = e.index;
			console.log(index);
			if (index == 0) {
				this.modalName = 'DrawerModalR';
			}
		},
		//是否打印单据
		isPrintOrder(type, BillID = "") {
			var that = this;
			if (type) {
				Api.showConfirm("是否打印单据", function(result) {
					if (result) {
						that.PrintOrder(false, BillID);
					} else {
						setTimeout(function() {
							if (!that.isBillCheckQx) {
								if (that.cgSettingLocation.djSh[0].state) {
									that.isBillCheck(true);
								}
								if (that.cgSettingLocation.djSh[1].state) {
									that.isBillCheck(false);
								}
							} else {
								that.isBillCheck(false);
							}
						}, 1000);
					}
				})
			} else {
				that.PrintOrder(false, BillID);
			}
		},
		//是否审核
		isBillCheck(type) {
			var that = this;
			if (this.BillType == 10) {
				Api.showTip("盘点单无法进行审核操作!");
				return;
			}
			if (type) {
				Api.showConfirm("是否审核单据", function(result) {
					if (result) {
						that.toBillCheck();
					} else {

					}
				})
			} else {
				that.toBillCheck();
			}
		},
		toBillCheck(isInput, BillID = "") {
			var that = this;
			let data = {
				BillType: this.BillType,
				BillID: this.BillID,
				BillName: this.BillName
			};
			Api.Bill_Check(data, function(res) {
				if (res.state) {
					if (res.data.ErrorMsg == '获取登录信息失败') {
						Api.showTip("登录超时!");
					} else if (res.data.ErrorMsg != "") {
						Api.showTip(res.data.ErrorMsg);
					} else {
						// that.isBillCheckSuc[that.isBillCheck] = checkCountList[that.isBillCheck];
						// that.isBillCheck++;
						Api.showTip("审核成功");
					}
				} else {

				}
				// that.toBillCheck(checkCountList, index, countSize);
			})
		},
		PrintOrder(isInput = true, BillID = "") {
			let data = {};
			let Save_M_Data_Json = {};
			if (!isInput) {
				Save_M_Data_Json = {
					Order_Number: this.BillNo,
					BillName: this.BillName,
					Printer: this.CreateName,
					BillID: this.BillID
				};
			} else {
				this.modalNames = null;
				Save_M_Data_Json = {
					Order_Number: this.BillNo,
					BillName: this.BillName,
					Printer: this.CreateName,
					BillID: this.BillID,
					PrintNum: this.printNum + "",
					PrintPCNumber: this.printCode + ""
				};
			}
			data = {
				Save_M_Data_Json: JSON.stringify(Save_M_Data_Json)
			}
			this.printNum = 1;
			this.current = 0;
			this.printCode = 1;
			var _this = this;
			Api.Add_Android_Print(data, function(res) {
				if (res.state) {
					if (res.data.ErrorMsg == '获取登录信息失败') {
						Api.showTip("登录超时");
					} else if (res.data.ErrorMsg != "") {
						Api.showTip(res.data.ErrorMsg);
					} else {
						Api.showTip("已发送打印指令");
						if (!isInput) {
							setTimeout(function() {
								if (!_this.isBillCheckQx) {
									if (_this.cgSettingLocation.djSh[0].state) {
										_this.isBillCheck(true);
									}
									if (_this.cgSettingLocation.djSh[1].state) {
										_this.isBillCheck(false);
									}
								} else {
									_this.isBillCheck(false);
								}
							}, 1000);
						}
					}
				}
			})
		},
		ycDy() {
			if (this.isChange) {
				this.$refs.settingOption._data.modalPrintName = "printSetting";
			} else {
				Api.showTip("请先查询单据");
			}
		},
		// //单据审核
		djSh() {
			if (this.isChange) {
				this.isBillCheck();
			} else {
				Api.showTip("请先查询单据");
			}
		},
		changeSetting(e) {
			this.cgSettingLocation = e.detail;
			this.isChangeShow = this.cgSettingLocation.GoodShowSimpleInfo[0].state;
		},
	}
}
